<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="js/layui/css/layui.css"  media="all">
  <script src="js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="js/layer/layer.js" type="text/javascript" charset="utf-8"></script>
	<script src="js/Global.js" type="text/javascript" charset="utf-8"></script>
  <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>

<table class="layui-hide" id="test" lay-filter="test"></table>


<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-xs" lay-event="teacher">评价</a>

</script>


<script src="js/layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

<script>



layui.use('table', function(){
  var table = layui.table;
  var newscript = document.createElement('script');
  newscript.setAttribute('type','text/javascript');
  newscript.setAttribute('src','js/Global.js');
  var head = document.getElementsByTagName('head')[0];
  head.appendChild(newscript);


   	 var id=window.globalConfig.id;
	 var ids2=window.globalConfig.id2;
	 var token=window.globalConfig.token;
	 /* alert(token) */
  table.render({
    elem: '#test'
	 ,

    url:'http://127.0.0.1:8080//teResult/teacherCheck?teacherid='+ids2
    /* ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板 */
    ,defaultToolbar: [/* 'filter' */ 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
      title: '提示'
      ,layEvent: 'LAYTABLE_TIPS'
      ,icon: 'layui-icon-tips'
    }]
    ,title: '用户数据表'
    ,cols: [[


      {field:'coursename', title:'课程名称', width:250}
      ,{field:'teachername', title:'教师名称', width:250}
	,{field:'cou', title:'评教人数', width:250}
	  ,{field:'classname', title:'班级名称', width:250}
	  ,{field:'sc', title:'平均分', width:250}
	  ]]
    ,page:{
	 		 layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
	 		         //,curr: 5 //设定初始在第 5 页
	 		         ,limit:10 //一页显示多少条
	 		         ,limits:[5,10,15]//每页条数的选择项
	 		         ,groups: 2 //只显示 2 个连续页码
	 		         ,first: "首页" //不显示首页
	 		         ,last: "尾页" //不显示尾页
	 	 }
  });

  //头工具栏事件
  table.on('toolbar(test)', function(obj){
    var checkStatus = table.checkStatus(obj.config.id);
    switch(obj.event){
      case 'getCheckData':
        var data = checkStatus.data;
        layer.alert(JSON.stringify(data));
      break;
      case 'getCheckLength':
        var data = checkStatus.data;
        layer.msg('选中了：'+ data.length + ' 个');
      break;
      case 'isAll':
        layer.msg(checkStatus.isAll ? '全选': '未全选');
      break;

      //自定义头工具栏右侧图标 - 提示
      case 'LAYTABLE_TIPS':
        layer.alert('这是工具栏右侧自定义的一个图标按钮');
      break;
    };
  });

  //监听行工具事件
  table.on('tool(test)', function(obj){
    var data = obj.data;
    //console.log(obj)
    if(obj.event === 'del'){
      layer.confirm('真的删除行么', function(index){
        obj.del();
        layer.close(index);
		  var indexid=obj.data.indexid;
		console.log(obj.data.indexid)


		$.ajax({

			 beforeSend: function(request) {
			     request.setRequestHeader("token", token);
			},
			type:"get",
			 url:"http://127.0.0.1:8080//index/delete",

			contentType:"application/x-www-form-urlencoded;charset=utf-8",
			data: {'indexid':indexid},
			success:function(msg){
				alert(msg);
			}
		})
      });
    } else if(obj.event === 'edit'){


		 var table = layui.table;
		var newscript = document.createElement('script');
		newscript.setAttribute('type','text/javascript');
		newscript.setAttribute('src','js/Global.js');
		var head = document.getElementsByTagName('head')[0];
		head.appendChild(newscript);


		 	 var id=window.globalConfig.id;

      layer.prompt({
        formType: 2
        ,value: data.email
      }, function(value, index){
        obj.update({
          email: value
        });
        layer.close(index);
      });
    }else if(obj.event=="teacher"){
				 var table = layui.table;
			var newscript = document.createElement('script');
			newscript.setAttribute('type','text/javascript');
			newscript.setAttribute('src','js/Global.js');
			var head = document.getElementsByTagName('head')[0];
			head.appendChild(newscript);


			 	 var id=window.globalConfig.id;
					var a=0;
			$.ajax({
				       type:"get",
				        url:"http://127.0.0.1:8080//teResult/findTccid",

				      contentType: "application/json;charset=utf-8",

				     data:{'tccid':obj.data.tccid,'userid':id},
						 success:function(msg){
							   if(msg.code==0){
									  layer.msg(msg.data, {time:1000, icon:5, shift:6},function(){
									 	 a=1;

									 });

								 }else{
									 var table = layui.table;
									 var newscript = document.createElement('script');
									 newscript.setAttribute('type','text/javascript');
									 newscript.setAttribute('src','js/Global.js');
									 var head = document.getElementsByTagName('head')[0];
									 head.appendChild(newscript);

									        /*  alert(obj.data.teacherid) */
									  	 var id=window.globalConfig.id;
									   layer.open({
									   type: 2,
									   area: ['700px', '450px'],
									   fixed: false, //不固定
									   maxmin: true,
									   content:'studentProblm.html?userid='+id+'&&userid2='+obj.data.tccid+'&&userid3='+obj.data.teacherid,

									 });
								 }
						 }
			})

		if(a==0){

		}







	}
  });
});
</script>


</body>
</html>
